package com.qys.livesMall.financial.service.impl;

import com.qys.livesMall.financial.model.dto.sys.FinancialOfflineDetailSaveDTO;
import com.qys.livesMall.financial.model.entity.FinancialOfflineDetail;
import com.qys.livesMall.financial.mapper.FinancialOfflineDetailMapper;
import com.qys.livesMall.financial.service.FinancialOfflineDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 线下理财明细 服务实现类
 * </p>
 *
 * @author
 * @since 2023-06-10
 */
@Service
public class FinancialOfflineDetailServiceImpl extends ServiceImpl<FinancialOfflineDetailMapper, FinancialOfflineDetail> implements FinancialOfflineDetailService {

    /**
     * 新增线下理财任务明细信息
     *
     * @param detailList {@link  FinancialOfflineDetailSaveDTO}
     * @param id         线下理财id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(List<FinancialOfflineDetailSaveDTO> detailList, Long id) {
        List<FinancialOfflineDetail> details = new ArrayList<>(detailList.size());

        detailList.stream().forEach(detailDTO -> {
            FinancialOfflineDetail detail = new FinancialOfflineDetail();
            detail.setOfflineId(id);
            detail.setSort(detailDTO.getSort());
            detail.setTime(detailDTO.getTime());
            details.add(detail);
        });

        saveBatch(details);
    }
}
